home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / term / term_47a_pch.lha / Source / gtlayout-38.3 / LTP_Storage.c < prev    next >
C/C++ Source or Header  |  1996-11-10  |  5KB  |  319 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. VOID
  15. LTP_GetStorage(ObjectNode *Node)
  16. {
  17.     if(Node->Storage)
  18.     {
  19.         LONG    Number = 0;
  20.         STRPTR    String = NULL;
  21.  
  22.         switch(Node->StorageType)
  23.         {
  24.             case STORAGE_BYTE:
  25.  
  26.                 Number = *(BYTE *)Node->Storage;
  27.                 break;
  28.  
  29.             case STORAGE_UBYTE:
  30.  
  31.                 Number = *(UBYTE *)Node->Storage;
  32.                 break;
  33.  
  34.             case STORAGE_WORD:
  35.  
  36.                 Number = *(WORD *)Node->Storage;
  37.                 break;
  38.  
  39.             case STORAGE_UWORD:
  40.  
  41.                 Number = *(UWORD *)Node->Storage;
  42.                 break;
  43.  
  44.             case STORAGE_LONG:
  45.  
  46.                 Number = *(LONG *)Node->Storage;
  47.                 break;
  48.  
  49.             case STORAGE_ULONG:
  50.  
  51.                 Number = *(ULONG *)Node->Storage;
  52.                 break;
  53.  
  54.             case STORAGE_STRPTR:
  55.  
  56.                 String = Node->Storage;
  57.                 break;
  58.         }
  59.  
  60.         switch(Node->Type)
  61.         {
  62.             case CHECKBOX_KIND:
  63.             case LISTVIEW_KIND:
  64.             case MX_KIND:
  65.             case CYCLE_KIND:
  66.             case PALETTE_KIND:
  67.             case SLIDER_KIND:
  68.             case SCROLLER_KIND:
  69. #if defined(DO_POPUP_KIND) && defined(DO_BOOPSI_KIND)
  70.             case POPUP_KIND:
  71. #endif
  72. #if defined(DO_TAB_KIND) && defined(DO_BOOPSI_KIND)
  73.             case TAB_KIND:
  74. #endif
  75. #ifdef DO_GAUGE_KIND
  76.             case GAUGE_KIND:
  77. #endif
  78.  
  79. #ifdef DO_TAPEDECK_KIND
  80.             case TAPEDECK_KIND:
  81. #endif    /* DO_TAPEDECK_KIND */
  82.  
  83.                 Node->Current = Number;
  84.                 break;
  85.  
  86.             case STRING_KIND:
  87.             case FRACTION_KIND:
  88. #ifdef DO_PASSWORD_KIND
  89.             case PASSWORD_KIND:
  90. #endif
  91.                 Node->Special.String.String = String;
  92.                 break;
  93.  
  94.             case INTEGER_KIND:
  95.  
  96.                 Node->Special.Integer.Number = Number;
  97.                 break;
  98. #ifdef DO_LEVEL_KIND
  99.             case LEVEL_KIND:
  100.  
  101.                 Node->Current = Number;
  102.                 break;
  103. #endif    /* DO_LEVEL_KIND */
  104.         }
  105.     }
  106. }
  107.  
  108.  
  109. /*****************************************************************************/
  110.  
  111.  
  112. VOID
  113. LTP_PutStorage(ObjectNode *Node)
  114. {
  115.     if(Node->Storage)
  116.     {
  117.         LONG    Number = 0;
  118.         STRPTR    String = NULL;
  119.  
  120.         switch(Node->Type)
  121.         {
  122.             case CHECKBOX_KIND:
  123.             case LISTVIEW_KIND:
  124.             case MX_KIND:
  125.             case CYCLE_KIND:
  126.             case PALETTE_KIND:
  127.             case SLIDER_KIND:
  128.             case SCROLLER_KIND:
  129. #if defined(DO_POPUP_KIND) && defined(DO_BOOPSI_KIND)
  130.             case POPUP_KIND:
  131. #endif
  132. #if defined(DO_TAB_KIND) && defined(DO_BOOPSI_KIND)
  133.             case TAB_KIND:
  134. #endif
  135. #ifdef DO_GAUGE_KIND
  136.             case GAUGE_KIND:
  137. #endif
  138.  
  139. #ifdef DO_TAPEDECK_KIND
  140.             case TAPEDECK_KIND:
  141. #endif    /* DO_TAPEDECK_KIND */
  142.                 Number = Node->Current;
  143.                 break;
  144.  
  145. #ifdef DO_PASSWORD_KIND
  146.             case PASSWORD_KIND:
  147.  
  148.                 String = Node->Special.String.RealString;
  149.                 break;
  150. #endif
  151.  
  152.             case STRING_KIND:
  153.             case FRACTION_KIND:
  154.  
  155.                 if(Node->Host)
  156.                     String = ((struct StringInfo *)Node->Host->SpecialInfo)->Buffer;
  157.                 else
  158.                     String = Node->Special.String.String;
  159.  
  160.                 if(Node->Type == FRACTION_KIND)
  161.                 {
  162.                     LTP_CopyFraction(Node->Special.String.RealString,String);
  163.                     String = Node->Special.String.RealString;
  164.                 }
  165.  
  166.                 break;
  167.  
  168.             case INTEGER_KIND:
  169.  
  170.                 if(Node->Host)
  171.                     Number = ((struct StringInfo *)Node->Host->SpecialInfo)->LongInt;
  172.                 else
  173.                     Number = Node->Special.Integer.Number;
  174.  
  175.                 break;
  176. #ifdef DO_LEVEL_KIND
  177.             case LEVEL_KIND:
  178.  
  179.                 Number = Node->Current;
  180.                 break;
  181. #endif    /* DO_LEVEL_KIND */
  182.         }
  183.  
  184.         switch(Node->StorageType)
  185.         {
  186.             case STORAGE_BYTE:
  187.  
  188.                 if(!String)
  189.                     *(BYTE *)Node->Storage = (BYTE)Number;
  190.  
  191.                 break;
  192.  
  193.             case STORAGE_UBYTE:
  194.  
  195.                 if(!String)
  196.                     *(UBYTE *)Node->Storage = (UBYTE)Number;
  197.  
  198.                 break;
  199.  
  200.             case STORAGE_WORD:
  201.  
  202.                 if(!String)
  203.                     *(WORD *)Node->Storage = (WORD)Number;
  204.  
  205.                 break;
  206.  
  207.             case STORAGE_UWORD:
  208.  
  209.                 if(!String)
  210.                     *(UWORD *)Node->Storage = (UWORD)Number;
  211.  
  212.                 break;
  213.  
  214.             case STORAGE_LONG:
  215.  
  216.                 if(!String)
  217.                     *(LONG *)Node->Storage = (LONG)Number;
  218.  
  219.                 break;
  220.  
  221.             case STORAGE_ULONG:
  222.  
  223.                 if(!String)
  224.                     *(ULONG *)Node->Storage = (ULONG)Number;
  225.  
  226.                 break;
  227.  
  228.             case STORAGE_STRPTR:
  229.  
  230.                 if(String)
  231.                     strcpy(Node->Storage,String);
  232.  
  233.                 break;
  234.         }
  235.     }
  236. }
  237.  
  238.  
  239. /*****************************************************************************/
  240.  
  241.  
  242. VOID
  243. LTP_CopyFraction(STRPTR To,STRPTR From)
  244. {
  245.     UBYTE DecimalPoint,c;
  246.     BOOL GotPoint;
  247.     STRPTR Orig;
  248.  
  249.         /* Skip leading junk. */
  250.  
  251.     while(*From != '.' && (*From < '0' || *From > '9') && *From != '\0')
  252.         From++;
  253.  
  254.         /* Skip extraenous zeroes. */
  255.  
  256.     while(From[0] == '0')
  257.         From++;
  258.  
  259.     Orig = To;
  260.  
  261.     DecimalPoint = (LTP_Locale ? LTP_Locale->loc_DecimalPoint[0] : '.');
  262.  
  263.         /* If the first character is just a decimal point, add a zero
  264.          * in front of it.
  265.          */
  266.  
  267.     if(*From == '.' || *From == DecimalPoint)
  268.         *To++ = '0';
  269.  
  270.     GotPoint = FALSE;
  271.  
  272.         /* Now copy and convert the number. */
  273.  
  274.     while(c = *From++)
  275.     {
  276.         if(c == DecimalPoint || c == '.')
  277.         {
  278.             if(!GotPoint)
  279.             {
  280.                 *To++ = '.';
  281.  
  282.                 GotPoint = TRUE;
  283.             }
  284.         }
  285.         else
  286.         {
  287.             if(c >= '0' && c <= '9')
  288.                 *To++ = c;
  289.         }
  290.     }
  291.  
  292.         /* If the string would remain blank,
  293.          * use a zero.
  294.          */
  295.  
  296.     if(Orig == To)
  297.         *To++ = '0';
  298.  
  299.         /* If we didn't get a decimal point, add one. */
  300.  
  301.     if(!GotPoint)
  302.     {
  303.         *To++ = '.';
  304.         *To++ = '0';
  305.     }
  306.  
  307.         /* Strip trailing zeroes if they follow the decimal point. */
  308.  
  309.     if(GotPoint)
  310.     {
  311.         while(To > Orig && To[-1] == '0' && To[-2] == '0')
  312.             To--;
  313.     }
  314.  
  315.         /* Terminate the string. */
  316.  
  317.     *To = '\0';
  318. }
  319.